package com.itheima.train.manager.configuration;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfiguration {

    // 声明队列
    @Bean(name = "back_stock_es_queue")
    public Queue backStockESQueue() {
        return QueueBuilder.durable("back_stock_es_queue").build() ;
    }

    // 声明交换机和队列的绑定关系
    @Bean
    public Binding trainExBindBackStockESQueue(@Qualifier(value = "train_manager_ex") Exchange exchange , @Qualifier(value = "back_stock_es_queue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("back_stock").noargs() ;
    }

    // 声明交换机
    @Bean(name = "train_manager_ex")
    public Exchange trainManagerExchange() {
        return ExchangeBuilder.directExchange("train_manager_ex").durable(true).build() ;
    }

    // 声明队列
    @Bean(name = "syn_stock_es_queue")
    public Queue synOrderStockEsQueue() {
        return QueueBuilder.durable("syn_stock_es_queue").build() ;
    }

    // 声明队列
    @Bean(name = "syn_seat_to_redis_queue")
    public Queue synSeatToRedisQueue() {
        return QueueBuilder.durable("syn_seat_to_redis_queue").build() ;
    }

    @Bean(name = "syn_riding_plan_to_redis_queue")
    public Queue synRidingPlanToRedisQueue() {
        return QueueBuilder.durable("syn_riding_plan_to_redis_queue").build() ;
    }

    @Bean(name = "syn_riding_plan_to_es_queue")
    public Queue synRidingPlanToESQueue() {
        return QueueBuilder.durable("syn_riding_plan_to_es_queue").build() ;
    }

    // 完成队列和交换机的绑定
    @Bean
    public Binding trainManagerExBindingSeatRedisQueue(@Qualifier(value = "train_manager_ex") Exchange exchange , @Qualifier(value = "syn_seat_to_redis_queue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("syn_seat").noargs() ;
    }

    @Bean
    public Binding trainManagerExBindingRidingPlanRedisQueue(@Qualifier(value = "train_manager_ex") Exchange exchange , @Qualifier(value = "syn_riding_plan_to_redis_queue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("syn_riding_plan").noargs() ;
    }

    @Bean
    public Binding trainManagerExBindingRidingPlanESQueue(@Qualifier(value = "train_manager_ex") Exchange exchange , @Qualifier(value = "syn_riding_plan_to_es_queue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("syn_riding_plan").noargs() ;
    }

    // 声明交换机和队列的绑定关系
    @Bean
    public Binding trainExBindOrderStockEsQueue(@Qualifier(value = "train_manager_ex") Exchange exchange , @Qualifier(value = "syn_stock_es_queue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("syn_stock").noargs() ;
    }

}
